package com.study.leetcode;

import java.util.ArrayList;
import java.util.List;

public class Solution_144 {
    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        doPreorderTraversal(root, result);
        return result;
    }

    private void doPreorderTraversal(TreeNode root, List<Integer> result) {
        if (root != null) {
            doPreorderTraversal(root.left, result);
            doPreorderTraversal(root.right, result);
            result.add(root.val);
        }
    }
}
